package com.pets.web.controller.api;


import com.pets.common.annotation.Log;
import com.pets.common.annotation.RateLimiter;
import com.pets.common.core.controller.BaseController;
import com.pets.common.core.domain.AjaxResult;
import com.pets.common.core.domain.R;
import com.pets.common.core.page.TableDataInfo;
import com.pets.common.enums.BusinessType;
import com.pets.common.enums.LimitType;
import com.pets.common.utils.SecurityUtils;
import com.pets.web.dto.SoldDto;
import com.pets.web.entity.PetsComment;
import com.pets.web.entity.PetsGoods;
import com.pets.web.service.IPetsGoodsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.util.List;

/**
 * <p>
 * 商品表 前端控制器
 * </p>
 *
 * @author zhurenwang
 * @since 2024-05-25
 */
@Api(tags = "商品详情页面接口")
@Validated
@RestController
@RequestMapping("/api/goods")
public class ApiPetsGoodsController extends BaseController {

    @Autowired
    private IPetsGoodsService petsGoodsService;

//    @GetMapping("/list")
//    public TableDataInfo list(PetsGoods petsGoods){
//        startPage();
//        if (!SecurityUtils.isAdmin(SecurityUtils.getUserId())){
//            petsGoods.setSysUserId(SecurityUtils.getUserId());
//        }
//        List<PetsGoods> list = petsGoodsService.list(petsGoods);
//        return getDataTable(list);
//    }

    @ApiOperation("获取商品详情")
    //@RateLimiter(time = 5, count = 50, limitType = LimitType.IP)
    @GetMapping("/getGoods/{goodsId}")
    public R<PetsGoods> getGoods(@ApiParam("商品id") @NotNull @PathVariable Integer goodsId) {
        return R.ok(petsGoodsService.getGoodsById(goodsId));
    }

    @ApiOperation("获取已售 && xx人已购买")
    //@RateLimiter(time = 5, count = 50, limitType = LimitType.IP)
    @GetMapping("/getSold/{goodsId}")
    public R<SoldDto> getSold(@ApiParam("商品id") @NotNull @PathVariable Integer goodsId) {
        return R.ok(petsGoodsService.getSoldInfo(goodsId));
    }

}
